<template>
  <div class="login-container">
    <div class="login-box">
      <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick" stretch=true>
        <el-tab-pane label="注册" name="second"></el-tab-pane>
      </el-tabs>
      <el-form :model="loginFormTel" style="width: 400px" rules="formRules">
        <el-form-item required prop="number">
          <el-input v-model="registerFrom.telephone" :prefix-icon="UserFilled" clearable placeholder="请输入11位手机号" />
        </el-form-item>
        <!-- <el-form-item required prop="email">
          <el-input v-model="registerFrom.email" :prefix-icon="UserFilled" clearable placeholder="请输入邮箱" />
        </el-form-item> -->
        <el-form-item required prop="username">
          <el-input v-model="registerFrom.username" :prefix-icon="UserFilled" clearable placeholder="请输入用户名" />
        </el-form-item>
        <el-form-item required prop="password">
          <el-input v-model="registerFrom.password" :prefix-icon="UserFilled" clearable placeholder="请输入密码" />
        </el-form-item>
        <el-form-item required prop="age">
          <el-input v-model="registerFrom.age" :prefix-icon="UserFilled" clearable placeholder="请输入年龄" />
        </el-form-item>
        <!-- <el-form-item label="" prop="number" clearable placeholder="请输入年龄">
          <el-input v-model.number="registerFrom.age" type="text" autocomplete="off" />
        </el-form-item> -->
        <el-form-item required prop="gender">
          <el-radio-group v-model="registerFrom.gender">
            <el-radio value="man">男</el-radio>
            <el-radio value="woman">女</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-select v-model="registerFrom.role" placeholder="选择权限" size="large" style="width: 240px">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
        <el-form-item required prop="password6" class="yanzhengma">
          <el-input v-model="registerFrom.password6" :prefix-icon="Lock" clearable placeholder="请输入6位验证码" />
        </el-form-item>
        <el-button type="primary" class="b2" style="width: 40%" @click="register">
          <el-text class="text2" size="large">发送验证码</el-text>
        </el-button>
        <el-button type="primary" class="b3" @click="register">
          <el-text class="text2" size="large">注册</el-text>
        </el-button>
      </el-form>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, watch, ref } from "vue"
import { UserFilled, Lock } from '@element-plus/icons-vue'
import request from "@/utils/request";
import { useRouter } from "vue-router";
import { ElMessage } from "element-plus";
import { ElTabs, ElTabPane, ImageProps } from 'element-plus';
import type { TabsPaneContext } from 'element-plus'
const router = useRouter();
const value = ref('')
const handleClick = (tab: TabsPaneContext, event: Event) => {
  console.log(tab, event)
}
const options = [
  {
    value: '1',
    label: '普通用户',
  },
  {
    value: '2',
    label: 'VIP用户',
  },
  {
    value: '3',
    label: '发型师',
  },
  {
    value: '4',
    label: '管理员',
  },
]

let enableLogin = ref(false);

let registerFrom = reactive({
  id: '',
  username: '',
  password: '',
  telephone: '',
  gender: '',
  age: '',
  role: '1',//1为普通用户，2为vip用户,3为发型师,4是管理员
  // email: '',
  avatar: '',//图片头像
  created_at: '',//创建时间
  updated_at: ''// 更新时间
})

// watch(() => [loginForm.username, loginForm.password], () => {
//   enableLogin.value = loginForm.username.length > 0 && loginForm.password.length > 0
// }, { immediate: true })

const formRules = reactive({
  username: { required: true, message: '请输入账号', trigger: 'blur' },
  password: { required: true, message: '请输入密码', trigger: 'blur' }
})

// function login() {
//   request.post('/api/users/login', loginForm)
//     .then(res => {
//       if (res.code == '210') {
//         ElMessage.success("登录成功")
//         localStorage.setItem('token', res.data)
//         router.push("/post")
//       } else {
//         ElMessage.error(res.msg)
//       }
//     }).catch(error => {
//       console.log(error)
//     })
// };

function register() {
  router.push("/register")
  request.post('/api/users/register', registerFrom)
    .then(res => {
      if (res.code == '210') {
        ElMessage.success("注册成功")
        localStorage.setItem('token', res.data)
        router.push("/login")
      } else {
        ElMessage.error(res.msg)
      }
    }).catch(error => {
      console.log(error)
    })
};

//年龄
// import type { FormInstance } from 'element-plus'

// const formRef = ref<FormInstance>()

// const numberValidateForm = reactive({
//   age: '',
// })

// const submitForm = (formEl: FormInstance | undefined) => {
//   if (!formEl) return
//   formEl.validate((valid) => {
//     if (valid) {
//       console.log('submit!')
//     } else {
//       console.log('error submit!')
//     }
//   })
// }

// const resetForm = (formEl: FormInstance | undefined) => {
//   if (!formEl) return
//   formEl.resetFields()
// }





</script>

<style  scoped>
.yanzhengma {
  width: 200px;
}

.b3 {
  width: 100%;
}

.demo-tabs {
  width: 500px;
}

.el-form {
  /*居中 */
  margin-left: 80px;
}

.el-input {
  width: 500px;
  height: 50px;
}


/* .el-tabs__item.is-active {
    color: #ffb800;
} */

.login-container {
  min-height: 100vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background-size: cover;
  background-image: url("@/assets/背景idea——把回形针换成剪刀吹风机等理发用品.jpg");


}


.login-box {
  height: 700px;
  width: 600px;
  /*距离左侧800px */
  margin-left: 800px;
  /*颜色*/
  background-color: #fff;
  /*不透明度 */
  opacity: 0.9;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  padding: 30px;
  border-radius: 15px;
}

.yanzhengma {
  width: 200px;
}

.el-button {
  height: 50px;
  margin: 5px;
  background-color: #be69eb;
  border-color: #be69eb;
  margin-top: 0px;
  margin-left: 0px;
}

.b2 {
  /*距离左侧30px */
  float: right;
  margin-right: 0px;
  margin-top: -90px;
}

.b4 {
  /*距离左侧30px */
  float: right;
  margin-right: 0px;

}

.a1 {
  float: right;
  margin-right: 100px;
  margin-top: 40px;

}

/*按钮触发颜色 */
.el-button:hover,
.el-button:focus {
  background-color: #fff;
  /* 自定义颜色 */
  border-color: #be69eb;
  /* 边框颜色 */
  color: #ffffff;
  /* 文字颜色 */
}

.c1-true-label {
  background-color: #ffb800;
}

.text2 {
  color: #000;
}

.a2 {
  color: #ffb800;
  text-decoration: none;
}

.a2:hover {
  color: #ffb800;

}
</style>